<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            max-width: 600px;
            margin: auto;
            padding-top: 100px;
        }

        ul {
            list-style: none;
            border: 1px solid #000;
            min-width: 220px;
            min-height: 300px;
        }

        .inner {
            margin-top: 40px;
            display: flex;
            justify-content: space-between;
        }

        li {
            padding: 10px;
            border-bottom: 1px dashed #ccc;
        }

        .mid {
            display: flex;
            flex-direction: column;
            justify-content: space-around;
        }

        .left>div,
        .right>div {
            padding: 10px;
        }
    </style>
</head>

<body>
    <div class="box">
        <h3>穿梭框</h3>
        <div class="inner">
            <div class="left">
                <div>
                    <input type="checkbox" class="all">
                    <span>全选</span>
                </div>
                <ul class="u-left">
                    <li>
                        <input type="checkbox">
                        <span>周瑜</span>
                    </li>
                    <li>
                        <input type="checkbox">
                        <span>小乔</span>
                    </li>
                    <li>
                        <input type="checkbox">
                        <span>诸葛亮</span>
                    </li>
                    <li>
                        <input type="checkbox">
                        <span>赵云</span>
                    </li>
                    <li>
                        <input type="checkbox">
                        <span>马超</span>
                    </li>
                    <li>
                        <input type="checkbox">
                        <span>黄忠</span>
                    </li>
                </ul>
            </div>
            <div class="mid">
                <button class="ml">&lt;&lt;&lt;移动到左边</button>
                <button class="mr">移动到右边&gt;&gt;&gt;</button>
            </div>
            <div class="right">
                <div>
                    <input type="checkbox" class="all">
                    <span>全选</span>
                </div>
                <ul class="u-right">

                </ul>
            </div>
        </div>
    </div>
    <script>
        var leftAll = document.querySelector('.left .all')
        var rightAll = document.querySelector('.right .all')

        leftAll.addEventListener('click', function () {
            document.querySelectorAll('.u-left input').forEach(item => item.checked = this.checked)
        })
        rightAll.addEventListener('click', function () {
            document.querySelectorAll('.u-right input').forEach(item => item.checked = this.checked)
        })

        var uLeft = document.querySelector('.u-left');
        uLeft.addEventListener('click', function (e) {
            var tar = undefined;
            if (e.target.nodeName === 'LI') {
                tar = e.target.children[0]
            } else if (e.target.nodeName === 'SPAN') {
                tar = e.target.previousElementSibling;
            }
            tar && (tar.checked = !tar.checked)
            var cks = uLeft.querySelectorAll('input');
            var ckeds = Array.from(cks).filter(item => item.checked)
            leftAll.checked = cks.length === ckeds.length;
        })

        var uRight = document.querySelector('.u-right');
        uRight.addEventListener('click', function (e) {
            var tar = undefined;
            if (e.target.nodeName === 'LI') {
                tar = e.target.children[0]
            } else if (e.target.nodeName === 'SPAN') {
                tar = e.target.previousElementSibling;
            }
            tar && (tar.checked = !tar.checked)
            var cks = uRight.querySelectorAll('input');
            var ckeds = Array.from(cks).filter(item => item.checked)
            rightAll.checked = cks.length === ckeds.length;
        })

        var moveLeft = document.querySelector('.ml')
        var moveRight = document.querySelector('.mr')
        moveLeft.addEventListener('click', function () {
            Array.from(uRight.querySelectorAll('input')).filter(item => item.checked).forEach(item => { uLeft.append(item.parentElement); item.checked = false })
        })

        moveRight.addEventListener('click', function () {
            Array.from(uLeft.querySelectorAll('input')).filter(item => item.checked).forEach(item => { uRight.append(item.parentElement); item.checked = false })
        })
    </script>
</body>

</html>